package ca.camosun.bouncer.tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import ca.camosun.bouncer.game.Ball;

public class BallTest {

	Ball aBall;

	@Before
	public void setUp() throws Exception {
		aBall = new Ball(6, 6);
	}

	@Test
	public void noBounce() {
		assertTrue(aBall.getX() == 6);
		assertTrue(aBall.getY() == 6);
	}

	@Test
	public void bounceRight() {
		aBall.bounce(7, 0);
		assertTrue(aBall.getX() == 13);
		assertTrue(aBall.getY() == 6);
	}

	@Test
	public void bounceLeft() {
		aBall.bounce(-7, 0);
		assertTrue(aBall.getX() == -1);
		assertTrue(aBall.getY() == 6);
	}

	@Test
	public void bounceUp() {
		aBall.bounce(0, 7);
		assertTrue(aBall.getX() == 6);
		assertTrue(aBall.getY() == 13);
	}

	@Test
	public void bounceDown() {
		aBall.bounce(0, -7);
		assertTrue(aBall.getX() == 6);
		assertTrue(aBall.getY() == -1);

	}

	@Test
	public void isInBounds1x1() {
		aBall = new Ball(0, 0);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == true);

		aBall = new Ball(0, 1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(1, 0);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(1, 1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(0, -1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(-1, 0);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(-1, -1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(1, -1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);

		aBall = new Ball(-1, 1);
		assertTrue(aBall.isInBounds(0, 1, 0, 1) == false);
	}

	@Test
	public void isInBounds() {
		final int xMin = 0;
		final int xMax = 15;
		final int yMin = 0;
		final int yMax = 15;

		for (int x = xMin; x < xMax; x++) {
			for (int y = yMin; y < yMax; y++) {
				aBall = new Ball(x, y);
				assertTrue(aBall.isInBounds(xMin, xMax, yMin, yMax) == true);
			}
		}
	}

	@Test
	public void isUnderBounds() {
		final int xMin = 0;
		final int xMax = 15;
		final int yMin = 0;
		final int yMax = 15;

		for (int x = -xMax; x < xMin; x++) {
			for (int y = -yMax; y < yMin; y++) {
				aBall = new Ball(x, y);
				assertTrue(aBall.isInBounds(xMin, xMax, yMin, yMax) == false);
			}
		}
	}

	@Test
	public void isOverBounds() {
		final int xMin = 0;
		final int xMax = 15;
		final int yMin = 0;
		final int yMax = 15;

		for (int x = xMax; x < (xMax * 2); x++) {
			for (int y = yMax; y < (yMax * 2); y++) {
				aBall = new Ball(x, y);
				assertTrue(aBall.isInBounds(xMin, xMax, yMin, yMax) == false);
			}
		}
	}
}
